import {showMessage} from "/@/utils/util";
import {ref} from "vue";

const points = [
	{latitude: 39.997761, longitude: 116.478935},
	{latitude: 39.997825, longitude: 116.478939},
	{latitude: 39.998549, longitude: 116.478912},
	{latitude: 39.998555, longitude: 116.478998},
	{latitude: 39.998566, longitude: 116.479282},
	{latitude: 39.998528, longitude: 116.479658},
	{latitude: 39.998453, longitude: 116.480151},
	{latitude: 39.998302, longitude: 116.480784},
	{latitude: 39.998184, longitude: 116.481149},
	{latitude: 39.997997, longitude: 116.481573},
	{latitude: 39.997846, longitude: 116.481863},
	{latitude: 39.997718, longitude: 116.482072},
	{latitude: 39.997718, longitude: 116.482362},
	{latitude: 39.998935, longitude: 116.483633},
	{latitude: 39.998968, longitude: 116.48367},
	{latitude: 39.999861, longitude: 116.484648}
]


const centerLongitude = points.length ? points[parseFloat(points.length / 2)].longitude : 116.478935
const centerLatitude = points.length ? points[parseFloat(points.length / 2)].latitude : 39.997761

export const useRecord = () => {
	const recordStatus = ref(false)
	const modalVisible = ref(false)
	const fileName = ref('')
	const mapHeight = ref()
	const onChangeRecordStatus = () => {
		const newValue = !recordStatus.value
		if (!newValue) {
			// 结束录制
			modalVisible.value = true
			return;
		}
		recordStatus.value = newValue
	}

	const onCloseModal = () => {
		recordStatus.value = false
		modalVisible.value = false
	}

	const onConfirmModal = () => {
		if (!fileName.value.trim()) {
			showMessage("请输入路径名称")
			return
		}
		onCloseModal()
		recordStatus.value = false
		console.log('保存路径')
	}
	return {
		mapHeight,
		points,
		centerLongitude,
		centerLatitude,
		recordStatus,
		modalVisible,
		fileName,
		onChangeRecordStatus,
		onCloseModal,
		onConfirmModal
	}
}
